Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports C4F.DevKit.Calendar
Imports C4F.DevKit.Calendar.Components

Namespace C4F.DevKit.Calendar.Samples
	Public Partial Class AppointmentDialog
		Inherits Form
		' whether or not the appointment was already in the calendar (which means we're editing it)
		Private _apptExists As Boolean

		Public Sub New(ByVal calService As CalendarService)
			InitializeComponent()

			calendarService1 = calService
			_apptExists = False
		End Sub

		Public Sub New(ByVal calService As CalendarService, ByVal appt As Appointment)
			Me.New(calService)
			appointmentDetails1.Appointment = appt
			_apptExists = True
		End Sub

		Private Sub appointmentDetails1_Load(ByVal sender As Object, ByVal e As EventArgs)

		End Sub

		Public ReadOnly Property Appointment() As Appointment
			Get
				Return appointmentDetails1.Appointment
			End Get
		End Property

		Private Sub btnOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOK.Click
			Try
				If _apptExists Then
					calendarService1.EditAppointment(appointmentDetails1.Appointment)
				Else
					calendarService1.AddAppointment(appointmentDetails1.Appointment)
				End If

				CType(MdiParent, MainForm).RefreshAppointmentList()
				Close()
			Catch e1 As CalendarException
				MessageBox.Show("Appointment must have a subject, and the end of the appointment must be later or the same time as the start", "Invalid appointment")
			Catch e2 As Exception
				MessageBox.Show(String.Format("Error saving new appointment to calendar {0}. You may not have write permission on this file.", calendarService1.CalendarFilePath), "Error while adding new appointment")
			End Try

		End Sub

		Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
			Close()
		End Sub

		Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
'TODO: INSTANT VB TODO TASK: Assignments within expressions are not supported in VB.NET
'ORIGINAL LINE: Me.appointmentDetails1.AttendeesList.Add(New Attendee { Name = "ThisMe" });
			Me.appointmentDetails1.AttendeesList.Add(New Attendee With {.Name = "ThisMe"})
		End Sub
	End Class
End Namespace
